package com.twang.stock.task;

import com.alibaba.fastjson.JSONObject;
import com.twang.stock.dto.StockMinutesMessage;
import com.twang.stock.entity.DfcfBanKuaiMaoLiLv;
import com.twang.stock.rocketMq.RocketMQProducer;
import com.twang.stock.service.impl.ZhangTingBanServiceImpl;
import com.twang.stock.service.jinyan.HolidayService;

import com.twang.stock.task.old.BaseTask;
import com.twang.stock.threadPool.AsycTaskExecutorConfig;
import com.twang.stock.utils.date.DateUtils;
import com.twang.stock.utils.date.HolidayCopy;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @param ：
 * 每日14：57更新
 * 即时--http://data.10jqka.com.cn/funds/gnzjl/ajax/1/free/1/
 *             3日：http://data.10jqka.com.cn/funds/gnzjl/board/3/ajax/1/free/1/
 *             5日：http://data.10jqka.com.cn/funds/gnzjl/board/5/ajax/1/free/1/
 *           明细：http://q.10jqka.com.cn/gn/detail/code/300845/
 */
@Slf4j
@Component
public class ZhangTingJuJiaoJobTask extends BaseTask {

    @Autowired
    private HolidayService holidayService;


    @Autowired
    private RocketMQProducer rocketMQProducer;

    @Autowired
    private AsycTaskExecutorConfig asycTaskExecutorConfig;

   @Scheduled(cron = "0 0/1 * * * ?")
    public void excute() throws InterruptedException {
       if(!holidayService.isWorkDay(HolidayCopy.getRealToday())){
            return;
       }

       asycTaskExecutorConfig.taskQueueExecutor().execute(() -> {
           try {
               if(DateUtils.JudgeTime("09:15:00", "11:30:00")||DateUtils.JudgeTime("13:00:00", "15:00:00")){
                   extracted();
               }
           } catch (Exception e) {
               log.info("error = {}", e);
           }
           log.info("==========>    ZhangTingJuJiaoJobTask end!");
       });
    }

    public void extracted() {
        StockMinutesMessage message = new StockMinutesMessage();
        message.setMinutes(HolidayCopy.getHHmmss().substring(8, 12));
        message.setDate(HolidayCopy.getRealToday());
        message.setType(StockMinutesMessage.TYPE_ZHANG_TING_JU_JIAO);
        log.info(">>>>>>>>>>>> covertDTO  message={}",JSONObject.toJSONString(message));
        rocketMQProducer.sendOneWay(JSONObject.toJSONString(message));
    }
}
